#""" 4 串口通讯：REPL串口 """
# https://learn.adafruit.com/circuitpython-essentials/circuitpython-uart-serial

import board
import busio
import digitalio


import sys
import select

led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT

poll = select.poll()
poll.register(sys.stdin, select.POLLIN )

print("listen:")
led.value = False
while True:
    res = poll.poll()
    str_input = res[0][0].readline()
    print("Got " + ' '.join([hex(ord(i)) for i in str_input]))

    str_input = str_input.rstrip("\n")
    if str_input == "on":
        led.value = True
    if str_input == "off":
        led.value = False
